$(function () {
    $("#jqGrid").jqGrid({
        url: '../sys/loan/list',
        datatype: "json",
        colModel: [
			{ label: '贷款编号', name: 'loanId', index: 'loanId', width: 80, key: true },
			{ label: 'app编号', name: 'appId', index: 'appId', width: 80 },
			{ label: '实名', name: 'realName', index: 'realName', width: 80 },
			{ label: '电话', name: 'phone', index: 'phone', width: 80 }, 			
			{ label: '婚姻情况', name: 'marry', index: 'marry', width: 80,formatter: function(value, options, row){
				if(value === 0)return "未填写";if(value === 1)return "未婚";
				if(value === 2)return "已婚";if(value === 3)return "离异";
			}},
			{ label: '教育程度', name: 'edu', index: 'edu', width: 80, formatter: function(value, options, row){
				if(value === 0)return "未填写";if(value === 1)return "其他";
				if(value === 2)return "初中";if(value === 3)return "高中";if(value === 4)return "大专";
				if(value === 5)return "本科";if(value === 6)return "硕士";if(value === 7)return "博士";
			}},
			{ label: '工作情况', name: 'job', index: 'job', width: 80,
				formatter: function(value, options, row){
					if(value === 0)return "未填写";if(value === 1)return "其他";if(value === 2)return "全职";
					if(value === 3)return "兼职";if(value === 4)return "自由职业";if(value === 5)return "找工作中";
					if(value === 6)return "无业";if(value === 7)return "在校学生";
				}},
			{ label: '车产情况', name: 'car', index: 'car', width: 80,formatter: function(value, options, row){
				if(value === 0)return "未填写";if(value === 1)return "无";
				if(value === 2)return "有按揭";if(value === 3)return "无按揭";
			}},
			{ label: '房产情况', name: 'house', index: 'house', width: 80,formatter: function(value, options, row){
				if(value === 0)return "未填写";if(value === 1)return "无";
				if(value === 2)return "有按揭";if(value === 3)return "无按揭"; if(value === 4) return "租房";
				if(value === 5)return "其他";
			}},
			{ label: '就职公司', name: 'company', index: 'company', width: 80 },
			{ label: '公司电话', name: 'companyTel', index: 'companyTel', width: 80 },
			{ label: '月收入', name: 'income', index: 'income', width: 80 },
			{ label: '信用卡', name: 'creditCard', index: 'creditCard', width: 80 },
			{ label: '资料完成度', name: 'comple', index: 'comple', width: 80 },
			{ label: '养老保险', name: 'fosterOld', index: 'fosterOld', width: 80,formatter: function(value, options, row){
				if(value === 0)return "未填写";if(value === 1)return "无";
				if(value === 2)return "个人";if(value === 3)return "集体";
			}},
		],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});
var vm = new Vue({
	el:'#rrapp',
	data:{
		q:{
			realName: null
		},
		showList: true,
		title: null,
		loan: {},
		idCardPic:[],
		incomePic:[],
		housePic:[],
		carPic:[],
		creditPic:[]
	},

	methods: {
		query: function () {
			vm.reload();
		},

		search: function (event) {
			var loanId = getSelectedRow();
			if (loanId == null) {
				return;
			}
			vm.showList = false;
			vm.title = "查询";
			vm.getInfo(loanId);
		},


		getInfo: function (loanId) {
			$.get("/sys/loan/info/" + loanId, function (r) {
				console.log(r.loan);
				var incomePics = (r.loan.incomePic + "").split(',');
				var idCardPics = (r.loan.idcardPic + "").split(',');
				var carPics = (r.loan.carPic + "").split(',');
				var creditPics = (r.loan.creditPic + "").split(',');
				var housePics = (r.loan.housePic + "").split(',');
				vm.loan = r.loan;
				for (var i = 0; i < idCardPics.length; i++) {
					vm.idCardPic.push(idCardPics[i]);
				}
				for (var i = 0; i < incomePics.length; i++) {
					vm.incomePic.push(incomePics[i]);
				}
				for (var i = 0; i < carPics.length; i++) {
					vm.carPic.push(carPics[i]);
				}
				for (var i = 0; i < creditPics.length; i++) {
					vm.creditPic.push(creditPics[i]);
				}
				for (var i = 0; i < housePics.length; i++) {
					vm.housePic.push(housePics[i]);
				}
			});
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam', 'page');
			$("#jqGrid").jqGrid('setGridParam', {
				postData:{'realName': vm.q.realName},
				page: page
			}).trigger("reloadGrid");

		},
	}
});

